package u1project.client;

import u1project.common.Request;
import u1project.common.Response;

import java.io.*;
import java.net.Socket;
import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class U1Client {
    public static void main(String[] args) {
        try {
            Socket s=new Socket("192.168.100.85",8888);
            ObjectOutputStream oout = new ObjectOutputStream(s.getOutputStream());
            ObjectInputStream oin = new ObjectInputStream(s.getInputStream());
            int choice=0;
            Scanner sc=new Scanner(System.in);
            while (true){
                System.out.println("1:上传，2：登录，3：注册，9：退出");
                choice=sc.nextInt();
                sc.nextLine();
                if(choice==1){
                    System.out.println("请输入上传的文件名：");
                    String fileName=sc.nextLine();
                    File f=new File(fileName);
                    String n=f.getName();
                    byte b[]=new byte[(int) f.length()];
                    FileInputStream fin=new FileInputStream(f);
                    fin.read(b);
                    fin.close();
                    Request request=new Request("upload");
                    request.put("fileName",n);
                    request.put("content",b);
                    oout.writeObject(request);
                    oout.reset();
                    Response o =(Response) oin.readObject();
                    System.out.println("上传结果:"+o);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
